﻿
using System;
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using MDT_MonitorModel;

// Pour en savoir plus sur le modèle d'élément Page Détail de l'élément, consultez la page http://go.microsoft.com/fwlink/?LinkId=234232

namespace MDT_Metro_monitoring
{
    /// <summary>
    /// Page affichant les détails d'un élément au sein d'un groupe, offrant la possibilité de
    /// consulter les autres éléments qui appartiennent au même groupe.
    /// </summary>
    public sealed partial class ItemDetailPage : MDT_Metro_monitoring.Common.LayoutAwarePage
    {
        Computer c;
        
        public ItemDetailPage()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            // Allow saved page state to override the initial item to display
            if (pageState != null && pageState.ContainsKey("SelectedItem"))
            {
                navigationParameter = pageState["SelectedItem"];
            }

            // TODO: Create an appropriate data model for your problem domain to replace the sample data
            c = (Computer)navigationParameter;
            this.pageTitle.Text = c.Name;

            if (c.DartTicket == "" || c.DartTicket == null)
            {
                this.dartButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }

            if (c.VMHost == "" || c.VMHost == null)
            {
                this.vMConnectButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }

            this.DefaultViewModel["itemsViewSource"] = c;
        }

        /// <summary>
        /// Preserves state associated with this page in case the application is suspended or the
        /// page is discarded from the navigation cache.  Values must conform to the serialization
        /// requirements of <see cref="SuspensionManager.SessionState"/>.
        /// </summary>
        /// <param name="pageState">An empty dictionary to be populated with serializable state.</param>
        protected override void SaveState(Dictionary<String, Object> pageState)
        {
        }

        private void DartButton_Click_1(object sender, RoutedEventArgs e)
        {
            //var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"test.rdp");
            this.DefaultViewModel["popedUpItem"] = new popedUpItem("Dart Ip: ", c.DartIP, "Dart Port: ", c.DartPort, "Dart Ticket: ", c.DartTicket);
            this.popUp.IsOpen = true;
        }

        private void MstscButton_Click_1(object sender, RoutedEventArgs e)
        {
            //var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"test.rdp");
            this.DefaultViewModel["popedUpItem"] = new popedUpItem("Computer IP: ", c.DartIP, "", "", "", "");
            this.popUp.IsOpen = true;
        }

        private void VmButton_Click_1(object sender, RoutedEventArgs e)
        {
            //var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"test.rdp");
            this.DefaultViewModel["popedUpItem"] = new popedUpItem("VMHost: ", c.VMHost, "VM Name: ", c.VMName, "", "");
            this.popUp.IsOpen = true;
        }


        private void ClosePopupButton(object sender, RoutedEventArgs e)
        {
            this.popUp.IsOpen = false;
        }

    }

    public class popedUpItem
    {

        public string text1 { get; set; }

        public string text2 { get; set; }

        public string text3 { get; set; }

        public string data1 { get; set; }

        public string data2 { get; set; }

        public string data3 { get; set; }

        public popedUpItem(string text1, string data1, string text2, string data2, string text3, string data3)
        {
            this.data1 = data1;
            this.data2 = data2;
            this.data3 = data3;

            this.text1 = text1;
            this.text2 = text2;
            this.text3 = text3;
        }
    }
}
